requirejs.config({
    baseUrl: "js/",
    paths: {
        "jquery": "/common/vendor/jquery-2.1.4/jquery-2.1.4.min",
        "base": "/common/scripts/base",
        "ajax": "/common/scripts/ajax",
        "local": "/common/scripts/local",
        "file": "/common/scripts/file",
        "swiper": "/common/vendor/swiper-4.5/swiper.min",
        "chart": "/common/charts/chart",
        "underscore": "/common/vendor/underscore-1.8.3/underscore.min",
        "dataHandling": "data-handling",
    },
    shim: {
        'underscore': {
            deps: ['dataHandling'],
            exports: "_"
        }
    }
});

require(["jquery", "base", "ajax", "local", "file", "swiper", "chart", "dataHandling", "underscore"], function($, base, ajax, local, file, swiper, chart, dataHandling, _) {
    "use strict";

    var process = function() {

        TalkingData.onHTSCEvent("page", "leaf304", "持仓综合分析", "", ""); //会员才埋 ?? 有问题

        var source = base.getUrlParameter("source") || "150000", //系统源 150001 普通 150002 信用  150003 限售股 150000 全账户
            account = base.getUrlParameter("account") || '($account)',
            currency = base.getUrlParameter("currency") || "401156", //401156 人民币 401344  港元 401840 美元
            dateType = base.getUrlParameter("dateType") || "03", // 01 近一个月 03 近三个月 06 近六个月 00 自定义时间段
            marketType = base.getUrlParameter("marketType") || "0", //市场类型 0 上证 1 深圳
            tempCache = "positon.js",
            tempKline = "tempkline.js";
        var _this = this;

        this.common = {
            testBtn: false, //是否是测试开关    
            source: source, //系统源
            currency: currency, //币种
            dateType: dateType, //日期
            account: account, //账户号
            marketType: marketType, //市场类型
            temp: tempCache, //缓存时间
            tempKline: tempKline, //保存K线访问权限
            daterange: dataHandling.getKLength(dateType), //获取K线数量
            kScreenMax: 45, //k线一屏显示多少个
            dateIndex: dataHandling.numberToIndex(dateType), //默认取 过去三个月
            //首屏接口
            firstInterface: {
                url: '/reqxml?action=27401&path=/account/hold_analysis/hold_analysis_index_one',
                data: {
                    clientNo: account,
                    source: source,
                    currency: currency,
                    dateType: dateType,
                    startDate: '',
                    endDate: '',
                    uid: '($weakaccount)',
                    wtoken: '($weaktoken)',
                },
                loadEnd: false, //是否加载完成
                run: false //是否加载过
            },
            //次屏接口
            secondInterface: {
                url: '/reqxml?action=27401&path=/account/hold_analysis/hold_analysis_index_two',
                data: {
                    clientNo: account,
                    source: source,
                    currency: currency,
                    startDate: '',
                    endDate: '',
                    isShow: '',
                    dateType: dateType
                },
                loadEnd: false, //是否加载完成
                run: false //是否加载过
            },
            //日期买卖点数据
            buySellPoint: {
                url: '/reqxml?action=27401&path=/account/hold_analysis/buy_sell_point',
                data: {
                    clientNo: account,
                    source: source,
                    currency: currency,
                    date: '',
                    page: 1,
                    pageSize: 4,
                    dateType: dateType
                },
                loadEnd: false, //是否加载完成
                run: false //是否加载过
            },
            //获取会员等级
            UserLevelInterface:{
            	url: '/reqxml?action=27006&path=/member/get_vip_info',
            	data: {
                    uid: '($weakaccount)',
                    wtoken: '($weaktoken)',
            	}
            },
            //页面链接跳转
            linkUrl: {
                //收益分析
                incomeAnalysisUrl: function() {
                    var _startDate = _this.renderData.startDate,
                        _endDate = _this.renderData.endDate;

                    TalkingData.onHTSCEvent("click", "leaf304", "持仓综合分析", "", "点击查看更多");

                    return 'http://action:10061/?shownavigationbar=1&&type=9&&topcolor=F64843&&fullscreen=1&&url=/zlcftajax/information/position/income-analysis.htm?startDate=' + _startDate + '&endDate=' + _endDate + '&dateType=' + _this.common.dateType;
                },
                //股票搜索
                searchUrl: function() {
                    var _startDate = _this.renderData.startDate,
                        _endDate = _this.renderData.endDate;

                    TalkingData.onHTSCEvent("click", "leaf304", "持仓综合分析", "", "请输入股票代码");

                    return 'http://action:10061/?shownavigationbar=1&&type=9&&topcolor=F64843&&fullscreen=1&&url=/zlcftajax/information/position/search.htm?type=0&startDate=' + _startDate + '&endDate=' + _endDate + '&dateType=' + _this.common.dateType;
                },
                //买卖点分析
                businessAnalysisUrl: function() {
                    var _date = _this.renderData[_this.common.riseType].dateCurrent,
                        _tradeNum = _this.renderData.buySellList[_date].tradeNum,
                        _buyNum = _this.renderData.buySellList[_date].buyNum,
                        _sellNum = _this.renderData.buySellList[_date].sellNum;

                    TalkingData.onHTSCEvent("click", "leaf304", "持仓综合分析", "", "查看所有买卖点明细");

                    return 'http://action:10061/?shownavigationbar=1&&type=9&&topcolor=F64843&&fullscreen=1&&url=/zlcftajax/information/position/business-analysis.htm?date=' + _date + '&totalNum=' + _tradeNum + '&buyNum=' + _buyNum + '&sellNum=' + _sellNum;
                },
                //自定义时间
                customTimeUrl: function() {

                    TalkingData.onHTSCEvent("click", "leaf304", "持仓综合分析", "", "选择日期下拉菜单选项详情_自定义时间");

                    return 'http://action:10061/?shownavigationbar=1&&type=9&&topcolor=F64843&&fullscreen=1&&url=/zlcftajax/information/position/custom-time.htm?source=' + source + '&currency=' + currency + '&type=0';
                },
                //个股详情
                stockDetail: function(index) {
                    var _startDate = _this.renderData.startDate,
                        _endDate = _this.renderData.endDate,
                        _list = _this.renderData.earningsExplain.list;

                    // 融资融券 | 普通交易 ??
                    TalkingData.onHTSCEvent("click", "leaf304", "持仓综合分析", "", "收益分析_持仓股详情|zh=" + (dataHandling.getFuse(_list[index].source) ? "融资融券" : "普通交易") + "|code=" + _list[index].stockCode + "|name=" + _list[index].stockName);

                    return 'http://action:10061/?shownavigationbar=1&&type=9&&topcolor=F64843&&fullscreen=1&&url=/zlcftajax/information/position/stockDetail.htm?isFouse=' + dataHandling.getFuse(_list[index].source) + '&source=' + _list[index].source + '&currency=' + currency + '&startDate=' + _startDate + '&endDate=' + _endDate + '&stockName=' + encodeURIComponent(_list[index].stockName) + '&stockCode=' + _list[index].stockCode + '&marketCode=' + _list[index].marketCode;
                },
                //买卖点分析个股详情
                buyStockDetail: function(index) {

                    var _startDate = _this.renderData.startDate,
                        _endDate = _this.renderData.endDate,
                        _list = _this.renderData.buySellList[_this.renderData[_this.common.riseType].dateCurrent].detailInfo.zlist;

                    //融资融券和普通账户
                    TalkingData.onHTSCEvent("click", "leaf304", "持仓综合分析", "", "买卖点分析_持仓股详情|zh=" + (dataHandling.getFuse(_list[index].source) ? "融资融券" : "普通交易") + "|code=" + _list[index].stockCode + "|name=" + _list[index].stockName);

                    return 'http://action:10061/?shownavigationbar=1&&type=9&&topcolor=F64843&&fullscreen=1&&url=/zlcftajax/information/position/stockDetail.htm?isFouse=' + dataHandling.getFuse(_list[index].source) + '&source=' + _list[index].source + '&currency=' + currency + '&startDate=' + _startDate + '&endDate=' + _endDate + '&stockName=' + encodeURIComponent(_list[index].stockName) + '&stockCode=' + _list[index].stockCode + '&marketCode=' + _list[index].marketCode;
                },
                //会员制首页
                memberDetail: function() {
                    //缓存数据到本地供其它页面使用
                    return 'http://action:10092/?jsfuncname=GetUserLevel()';
                },
                //升级链接
                upgradeUrl:function(){
                    TalkingData.onHTSCEvent("page", "leaf304", "持仓综合分析", "", "升级VIP会员");
                	return 'http://action:10061/?fullscreen=1&&topcolor=565E87&&shownavigationbar=1&&url=/zlcftajax/internet-account/my-account/member/member-upgrade.htm?curLevel='+ _this.renderData.userLevel +'&toLevel=1&source=0';
                }
            },
            run: [0, 0], //上证 深圳 是否加载过 0没有 1加载过
            riseCode: ['1A0001', '2A01'],
            riseType: 0 //当前tab是上证还是深圳 0上证 1深证
        };

        //前台显示数据
        this.renderData = {
            0: {}, //上证K线数据
            1: {}, //深圳K线数据
            currency: dataHandling.getCurrency(currency),
            riseType: 0, //当前tab 0上证 1深圳
            startDate: '', //开始时间
            endDate: '' //结束时间
        };

 
        this.init();
 		window.GetUserLevel = function(){
 			_this.getUserLevel().then(function(level){
 				if(parseFloat(level)>=1){
 					//可以看K线
 					_this.init();
 				}else{
                    local.save({
                        D_MEMBER: 1
                    }, function(obj) {}); 	
                   	_this.renderData.userLevel = level;		
 					base.href(_this.common.linkUrl.upgradeUrl());
 					//升级看K线
 				}
 			});
 		};
        window.GoBackOnLoad = function() {
            _this.isCacheDate(function() {
                _this.init();
            });

            //进过会员页面了
            local.read({
                D_MEMBER: ""
            }, function(obj) {
                if (obj.D_MEMBER === "1") {
                    local.save({
                        D_MEMBER: ""
                    }, function() {
                        _this.init();
                    });
                }
            });
        };
    };

    process.prototype = {
        /**
         * [init 初始化]
         * @return {[type]} [description]
         */
        init: function() {
            var _this = this;
                _this.getData();
            // file.readAll(_this.common.tempKline, function(fileData) {
            //     _this.renderData.isCacheKline = fileData.isCacheKline;
            //     _this.getData();
            // });
        },
        /**
         * [getUserLevel 获取会员等级]
         * @return {[type]} [description]
         */
        getUserLevel:function(){
        	var _this = this;
        	var dtd = $.Deferred();
        	ajax.runWeak(this.common.UserLevelInterface.url, this.common.UserLevelInterface.data, function(data) {
        	    var bin = data.BINDATA;
        	    var code = $(bin).find("flag").attr("code");
        	    var level = $(bin).find("memberInfo").attr('level');
        	    var msg = $(bin).find("flag").attr('msg');
        	    if (code === '0') {
        	    	dtd.resolve(level);
        	    } else {
        	        dtd.reject();
        	    }
        	}, function(data) {
				dtd.reject();
        	});
        	return dtd.promise();
        },
        /**
         * [isCacheDate 判断是否有缓存日期]
         * @return {[type]} [description]
         */
        isCacheDate: function(callback) {
            var _this = this;
            file.readAll(this.common.temp, function(data) {
                if (data.startDate && data.endDate) {
                    var startTxtDate = dataHandling.formatDate(data.startDate, 0),
                        endTxtDate = dataHandling.formatDate(data.endDate, 0),
                        startDate = dataHandling.formatDate(data.startDate, 1),
                        endDate = dataHandling.formatDate(data.endDate, 1);
                    //更新第一屏 接口入参 开始时间 结束时间
                    _this.common.firstInterface.data.startDate = startDate;
                    _this.common.firstInterface.data.endDate = endDate;
                    //更新第一屏 接口入参 开始时间 结束时间
                    _this.common.secondInterface.data.startDate = startDate;
                    _this.common.secondInterface.data.endDate = endDate;

                    _this.renderData.startDate = startDate;
                    _this.renderData.endDate = endDate;
                    _this.common.dateIndex = 3; //调整为自定义时间索引
                    _this.common.dateType = "00"; //自定义时间类别
                    callback && callback();
                }
            });
        },
        /**
         * [getKData 获取指数线]
         * @param  {[type]}   code       [1A0001上证]
         * @param  {[type]}   marketCode [市场代码]
         * @param  {[type]}   start      [开始日期 : xxxx-xx-xx]
         * @param  {[type]}   end        [结束日期 : xxxx-xx-xx]
         * @param  {Function} fn         [回调函数]
         * @return {[type]}              [description]
         */
        getKData: function(start, end, fn) {
            var dtd = $.Deferred();
            var _this = this;
            base.href("http://action:80014/?stockcode=" + this.common.riseCode[this.common.riseType] + "&&daterange=" + this.common.daterange + "&&jsfuncname=KdateFn");
            window.KdateFn = function(data) {
                var tm = typeof(data) == "object" ? data : JSON.parse(data),
                    _list = tm.list,
                    _list_self = [];
                var _start = new Date(start).getTime();
                var _end = new Date(end).getTime();
                var count = 0;

                for (var i = 0; i < _list.length; i++) {
                    var _time = new Date(_list[i][0]).getTime();
                    if (_time >= _start) {
                        var preClosePrice = _list[i - 1][4]; //上个交易日收盘价  
                        var currentClosePrice = _list[i][4]; //选中交易日收盘价  
                        var range = ((currentClosePrice - preClosePrice) / preClosePrice * 100).toFixed(2); //涨跌幅度 (当前收盘价 - 上一交易日收盘价) / 上一交易日收盘价  
                        count++;
                        if (count <= _this.common.kScreenMax) {
                            _list_self.push([dataHandling.formatDate(_list[i][0], 1), _list[i][3], _list[i][4], _list[i][2], _list[i][1], range]); //开盘 收盘 最低 最高 涨幅                         
                            continue;
                        }
                        if (_time <= _end) {
                            _list_self.push([dataHandling.formatDate(_list[i][0], 1), _list[i][3], _list[i][4], _list[i][2], _list[i][1], range]); //开盘 收盘 最低 最高 涨幅
                        } else {
                            break;
                        }
                    }
                }
                var klist = {
                    list: _list_self,
                    max: _.max(_list_self, function(value) { return parseFloat(value[4]) })[4],
                    min: _.min(_list_self, function(value) { return parseFloat(value[3]) })[3],
                }
                
                base.log(JSON.stringify(klist));
                dtd.resolve(klist);
                /*                fn && fn({
                                    list: _list_self,
                                    max: _.max(_list_self, function(value) { return value[4] })[4],
                                    min: _.min(_list_self, function(value) { return value[3] })[3],
                                });*/
            };
            return dtd.promise();
        },
        /**
         * [getData 获取页面数据]
         * @return {[type]} [description]
         */
        getData: function(obj) {
            var _this = this;
            //清空 第一屏数据状态
            this.common.firstInterface.loadEnd = false;
            this.common.firstInterface.run = false;
            this.common.firstInterface.data.dateType = this.common.dateType;
            //清空 第二屏数据状态
            this.common.secondInterface.loadEnd = false;
            this.common.secondInterface.run = false;
            this.common.secondInterface.data.dateType = this.common.dateType;
            //重置 买卖点数据
            this.common.buySellPoint.data.dateType = this.common.dateType;
            //k线条数变更     
            this.common.daterange = dataHandling.getKLength(this.common.dateType);
            // 清空运行记录
            this.common.run = [0, 0];
            // 初始化为上证指数
            this.common.riseType = 0;
            // 清空保存的页面数据
            this.renderData = {
                0: {}, //上证K线数据
                1: {}, //深圳K线数据
                riseType: 0, //当前tab 0上证 1深圳,
                currency: _this.renderData.currency,
                startDate: _this.renderData.startDate,
                endDate: _this.renderData.endDate,
                isCacheKline: _this.renderData.isCacheKline
            };
            //获取首屏数据
            _this.getFirstScreen();
        },
        /**
         * [getFirstScreen 获取首屏数据]
         * @return {[type]} [description]
         */
        getFirstScreen: function() {
            var _this = this;
            this.common.firstInterface.run = true;
            ajax.run(this.common.firstInterface.url, this.common.firstInterface.data, function(xml) {
                file.deleteAll(_this.common.temp, function(data) {}); // 清空本地日期记录
                _this.common.firstInterface.loadEnd = true; //接口加载完           
                var data = $.parseJSON(xml.BINDATA);
                if (data.code === "0") {
                    if (data.data.dateList && data.data.dateList.length) {
                        _this.renderFirstScreen(data.data);
                    } else {
                        base.log("日期列表取不出来");
                    }
                } else {
                    $('.container').html(_.template($('#main-empty-tpl').html())({
                        data: []
                    }));
                    _this.bindEvent();
                }
            }, function(xml) {
                $('.container').html(_.template($('#main-empty-tpl').html())({
                    data: []
                }));
                _this.bindEvent();
            });
        },
        /**
         * [renderFirstScreen 第一屏页面渲染]
         * @return {[type]} [description]
         */
        renderFirstScreen: function(data) {
            var _this = this;
            this.renderData = _.extend(this.renderData, data);
            this.renderData.dateIndex = this.common.dateIndex; //页面展示当前显示位
            //不是自定义日期时
            if (this.common.dateIndex != 3) {
                //页面展示日期设置
                this.renderData.startDate = this.renderData.dateList[this.common.dateIndex].startDateParam;
                this.renderData.endDate = this.renderData.dateList[this.common.dateIndex].endDateParam;
                //第二屏开始 结束日期设置
                this.common.secondInterface.data.startDate = this.renderData.dateList[this.common.dateIndex].startDateParam;
                this.common.secondInterface.data.endDate = this.renderData.dateList[this.common.dateIndex].endDateParam;
            }
            //获取数据给第二屏接口
            this.common.secondInterface.data.isShow = this.renderData.isShowKline; //是否显示k线 
            this.renderData.isCacheKline = this.renderData.isShowKline;
            var addCountProfit = Math.abs(this.renderData.earningsExplain.addProfit), //总盈利
                lossCountProfit = Math.abs(this.renderData.earningsExplain.lossProfit), //总亏损
                maxProfit = addCountProfit > lossCountProfit ? addCountProfit : lossCountProfit, //盈利亏损取最大值
                addCountPercent = addCountProfit / maxProfit * 100, //总盈利占比
                lossCountPercent = lossCountProfit / maxProfit * 100, //总亏损占比
                addPercent = Math.abs(this.renderData.earningsExplain.productInfo.maxProfitValue) / maxProfit * 100, //最大盈利占比
                lossPercent = Math.abs(this.renderData.earningsExplain.productInfo.minProfitValue) / maxProfit * 100; //最大亏损占比

            //保存比例
            this.renderData.earningsExplain.percent = {
                addCountPercent: addCountPercent, //总盈利占比
                lossCountPercent: lossCountPercent, //总亏损占比
                addPercent: addPercent, //最大盈利占比
                lossPercent: lossPercent //最大亏损占比
            };
            //缓存数据到本地供其它页面使用
            local.save({
                P_ACCOUNT: _this.common.account,
                P_SOURCE: _this.common.source,
                P_CURRENCY: _this.renderData.currency,
                P_CURRENCYTYPE: _this.common.currency,
                P_DATETYPE: _this.common.dateType,
                P_MARKETTYPE: _this.common.marketType,
                P_STARTDATE: _this.common.secondInterface.data.startDate,
                P_ENDDATE: _this.common.secondInterface.data.endDate,
                P_DATELIST: JSON.stringify(data.dateList)
            }, function(obj) {});

            //alert("renderFirstScreen="+JSON.stringify( data ));
            //首屏数据渲染
            $('.container').html(_.template($('#main-tpl').html())({
                data: _this.renderData
            }));

            base.log(_this.renderData);

            this.domAdjust();
            //页面绑定事件
            this.bindEvent();
            //收益分析 多栏切换
            this.swiper();
        },
        /**
         * [domAdjust 收益分析柱形调整]
         * @return {[type]} [description]
         */
        domAdjust: function() {
            var $profitMost = $(".profit-most"),
                $profitColumn = $(".profit-column"),
                $lossColumn = $(".loss-column"),
                $lossMost = $(".loss-most");
            //盈利最多位置处理            
            this.setDomPosition($profitMost, $(".profit-info .triangle"), $(".profit-info"));
            //亏损最多位置处理
            this.setDomPosition($lossMost, $(".loss-info .triangle"), $(".loss-info"));

            //总盈利- 最大盈利 极限值样式 
            if (parseFloat(this.renderData.earningsExplain.addProfit) > 0) {
                if ($profitColumn.height() < 6) {
                        $profitColumn.css({ "height": "6px" });
                        $profitMost.css({ "height": "2px" });
                }
            }
            //总亏损 - 最大亏损 极限值样式
            if (Math.abs(parseFloat(this.renderData.earningsExplain.lossProfit)) > 0) {
                if ($lossColumn.height() < 6) {
                        $lossColumn.css({ "height": "6px" });
                        $lossMost.css({ "height": "2px" }); 
                }
            }
        },
        /**
         * [getFirstScreen 获取次屏 买卖点和行业分布接口数据]
         * @return {[type]} [description]
         */
        getSecondData: function() {
            var _this = this;
            var dtd = $.Deferred();
            this.common.secondInterface.run = true;
            this.getSecondDataTime = ajax.run(_this.common.secondInterface.url, _this.common.secondInterface.data, function(xml) {
                _this.common.secondInterface.loadEnd = true;
                var data = $.parseJSON(xml.BINDATA);
                if (data.code === "0") {
                    dtd.resolve(data.data);
                } else {
                    dtd.reject();
                }
            }, function(xml) {
                dtd.reject();
                //alert("网络异常");
            });
            return dtd.promise();
        },
        /**
         * [getDaySellList 获取指定日期的买卖点]
         * @return {[type]} [description]
         */
        getDaySellList: function() {
            var _this = this;
            var dtd = $.Deferred();
            this.getDaySellListTime = ajax.run(_this.common.buySellPoint.url, _this.common.buySellPoint.data, function(xml) {
                var data = $.parseJSON(xml.BINDATA);
                if (data.code === "0") {
                    dtd.resolve(data.data)
                } else {
                    dtd.reject();
                }
            }, function(xml) {
                dtd.reject();
            });
            return dtd.promise();
        },
        /**
         * [getTestData 模拟k线]
         * @return {[type]} [description]
         */
        getTestData: function() {
            var _this = this;
            var kdata = {
                "list": [
                    ["20180102", "3314.03", "3348.33", "3314.03", "3349.05", "1.24"],
                    ["20180103", "3347.74", "3369.11", "3345.29", "3379.92", "0.62"],
                    ["20180104", "3371.00", "3385.71", "3365.30", "3392.83", "0.49"],
                    ["20180105", "3386.46", "3391.75", "3380.25", "3402.07", "0.18"],
                    ["20180108", "3391.55", "3409.48", "3384.56", "3412.73", "0.52"],
                    ["20180109", "3406.11", "3413.90", "3403.59", "3417.23", "0.13"],
                    ["20180110", "3414.11", "3421.83", "3398.84", "3430.21", "0.23"],
                    ["20180111", "3415.59", "3425.35", "3405.64", "3426.48", "0.10"],
                    ["20180112", "3423.88", "3428.94", "3417.98", "3435.42", "0.10"],
                    ["20180115", "3428.95", "3410.49", "3402.31", "3442.50", "-0.54"],
                    ["20180116", "3403.47", "3436.59", "3401.96", "3437.58", "0.77"],
                    ["20180117", "3438.58", "3444.67", "3430.51", "3465.20", "0.24"],
                    ["20180118", "3449.88", "3474.75", "3448.79", "3476.55", "0.87"],
                    ["20180119", "3481.62", "3487.86", "3474.29", "3498.43", "0.38"],
                    ["20180122", "3476.99", "3501.36", "3475.67", "3503.39", "0.39"],
                    ["20180123", "3504.34", "3546.51", "3504.34", "3547.22", "1.29"],
                    ["20180124", "3553.48", "3559.47", "3527.11", "3569.49", "0.37"],
                    ["20180125", "3555.17", "3548.31", "3528.03", "3571.48", "-0.31"],
                    ["20180126", "3535.49", "3558.13", "3534.20", "3574.91", "0.28"],
                    ["20180129", "3563.64", "3523.00", "3510.27", "3587.03", "-0.99"],
                    ["20180130", "3511.50", "3488.01", "3484.66", "3523.05", "-0.99"],
                    ["20180131", "3470.51", "3480.83", "3454.73", "3495.45", "-0.21"],
                    ["20180201", "3478.67", "3446.98", "3424.42", "3495.09", "-0.97"],
                    ["20180202", "3419.23", "3462.08", "3388.86", "3463.16", "0.44"],
                    ["20180205", "3411.67", "3487.50", "3406.24", "3487.72", "0.73"],
                    ["20180206", "3418.01", "3370.65", "3364.22", "3440.12", "-3.35"],
                    ["20180207", "3412.74", "3309.26", "3304.01", "3425.54", "-1.82"],
                    ["20180208", "3281.05", "3262.05", "3225.71", "3307.16", "-1.43"],
                    ["20180209", "3172.85", "3129.85", "3062.74", "3180.11", "-4.05"],
                    ["20180212", "3128.37", "3154.13", "3113.61", "3168.13", "0.78"],
                    ["20180213", "3176.11", "3184.96", "3176.11", "3219.22", "0.98"],
                    ["20180214", "3188.25", "3199.16", "3171.38", "3203.50", "0.45"],
                    ["20180222", "3237.57", "3268.56", "3234.12", "3269.92", "2.17"],
                    ["20180223", "3275.43", "3289.02", "3258.49", "3294.13", "0.63"],
                    ["20180226", "3307.30", "3329.57", "3281.62", "3335.99", "1.23"],
                    ["20180227", "3328.67", "3292.07", "3284.63", "3328.67", "-1.13"],
                    ["20180228", "3264.06", "3259.41", "3239.84", "3277.83", "-0.99"],
                    ["20180301", "3235.09", "3273.76", "3228.59", "3280.15", "0.44"],
                    ["20180302", "3248.45", "3254.53", "3242.27", "3269.94", "-0.59"],
                    ["20180305", "3255.87", "3256.93", "3236.72", "3269.40", "0.07"],
                    ["20180306", "3266.49", "3289.64", "3243.65", "3290.25", "1.00"],
                    ["20180307", "3288.86", "3271.67", "3264.76", "3308.41", "-0.55"],
                    ["20180308", "3268.35", "3288.41", "3261.55", "3289.50", "0.51"],
                    ["20180309", "3291.43", "3307.17", "3283.56", "3309.72", "0.57"],
                    ["20180312", "3319.21", "3326.70", "3313.56", "3333.56", "0.59"],
                    ["20180313", "3324.12", "3310.24", "3307.38", "3333.88", "-0.49"],
                    ["20180314", "3298.67", "3291.38", "3287.36", "3304.98", "-0.57"],
                    ["20180315", "3277.51", "3291.11", "3273.20", "3297.10", "-0.01"],
                    ["20180316", "3290.21", "3269.88", "3269.28", "3300.57", "-0.65"],
                    ["20180319", "3264.93", "3279.25", "3251.05", "3280.57", "0.29"],
                    ["20180320", "3257.22", "3290.64", "3252.43", "3292.57", "0.35"],
                    ["20180321", "3299.73", "3280.95", "3268.88", "3314.21", "-0.29"],
                    ["20180322", "3281.27", "3263.48", "3242.76", "3288.80", "-0.53"],
                    ["20180323", "3172.77", "3152.76", "3110.66", "3188.24", "-3.39"],
                    ["20180326", "3117.32", "3133.72", "3091.46", "3134.28", "-0.60"],
                    ["20180327", "3164.80", "3166.65", "3143.57", "3172.78", "1.05"],
                    ["20180328", "3130.57", "3122.29", "3117.53", "3165.21", "-1.40"],
                    ["20180329", "3127.26", "3160.53", "3098.25", "3174.51", "1.22"],
                    ["20180330", "3161.79", "3168.90", "3152.89", "3177.72", "0.26"]
                ],
                "max": "3587.03",
                "min": "3062.74"
            };

            this.renderData[this.common.riseType].kdata = kdata;
            if (this.common.secondInterface.loadEnd) {
                this.renderShenzhen();
            } else {
                this.getSecondData().done(function(data) {
                    var key = data.maxPoint; //最后一个日期                   
                    if (key && data.buySellList[key]) {
                        _this.common.buySellPoint.data.date = key;
                        _this.getDaySellList().done(function(list) {
                            data.buySellList[key].detailInfo.zlist = list.list;
                            _this.renderSecondScreen(data);
                        });
                    } else {
                        _this.renderSecondScreen(data);
                    }
                });
            }
        },
        /**
         * [getSecondProcess 第二屏数据处理过程]
         * @return {[type]} [description]
         */
        getSecondProcess: function() {
            var _this = this;
            this.common.secondInterface.run = true; //第二屏加载过，上拉加载第二屏失效
            this.common.run[this.common.riseType] = 1; //上证 或深证 运行

            var startData = dataHandling.formatDate(this.common.secondInterface.data.startDate, 3); //k线开始日期
            var endData = dataHandling.formatDate(this.common.secondInterface.data.endDate, 3); //k线结束日期
            if (this.common.testBtn) {
                this.getTestData();
            } else {
                if (this.renderData.isShowKline === "1") {
                    //显示开线
                    if (this.common.secondInterface.loadEnd) {
                        //深证
                        this.getKData(startData, endData).done(function(kdata) {
                            _this.renderData[_this.common.riseType].kdata = kdata;
                            _this.renderShenzhen();
                        });
                    } else {
                        //上证
                        $.when(this.getKData(startData, endData), this.getSecondData()).done(function(kdata, data) {
                            _this.renderData[_this.common.riseType].kdata = kdata;
                            var key = data.maxPoint; //最后一个日期                   
                            if (key && data.buySellList[key]) {
                                _this.common.buySellPoint.data.date = key;
                                _this.getDaySellList().done(function(list) {
                                    data.buySellList[key].detailInfo.zlist = list.list;
                                    _this.renderSecondScreen(data);
                                });
                            } else {
                                _this.renderSecondScreen(data);
                            }
                        });
                    }
                } else {
                    //不显示开线
                    this.getSecondData().done(function(data) {
                        _this.renderSecondScreen(data);
                    });
                }
            }
        },
        /**
         * [renderSecondScreen 第二屏页面渲染]
         * @return {[type]} [description]
         */
        renderSecondScreen: function(data) {
            var _this = this;
            var detail = {
                buyNum: '', //买入次数
                sellNum: '', //卖出次数
                tradeNum: '', //总次数
                profitLoss: '', //当日盈亏金额
                list: [],
                indexDate: '',
                range: '',
                currency: ''
            }
            this.renderData = _.extend(this.renderData, data); //行业分布

            if (data.industryDistribution.list) {
                //生成画饼图数据
                this.renderData = _.extend(this.renderData, { pieData: dataHandling.getPieData(_this.renderData.industryDistribution.list) });
                //生成期间操作数据
                this.renderData = _.extend(this.renderData, { pieDataList: dataHandling.getPieDataList(_this.renderData.industryDistribution.list) });
            }

            if (this.renderData.maxPoint) {
                var key = this.renderData.maxPoint;
                var info = this.renderData.buySellList[key];
                //保存最后一个买卖点索引
                var index = _this.renderData[_this.common.riseType].lastIndex = dataHandling.getIndexFromMostArray(_this.renderData[_this.common.riseType].kdata.list, key);

                //保存首个日期
                this.renderData[_this.common.riseType].dateCurrent = key;
                if (index >= 0) {
                    detail = {
                        buyNum: info.buyNum, //买入次数
                        sellNum: info.sellNum, //卖出次数
                        tradeNum: info.tradeNum, //总次数
                        profitLoss: info.detailInfo && info.detailInfo.profitLoss || 0, //当日盈亏金额
                        list: info.detailInfo && info.detailInfo.zlist || [],
                        indexDate: info.indexDate,
                        range: dataHandling.getRange(_this.renderData[_this.common.riseType].kdata.list[index][5]),
                        currency: _this.renderData.currency
                    };
                }

                this.renderData[this.common.riseType] = _.extend(this.renderData[this.common.riseType], { firstData: detail });
            }

            if (this.renderData.isShowKline != "1") {
                //无权限展示K线
                // file.deleteAll(_this.common.tempKline, function(fileData) {
                //     _this.renderData.isCacheKline = 0;
                //     _this.renderKP(false);
                // });
                    _this.renderData.isCacheKline = 0;
                    _this.renderKP(false);
            } else {
                // _this.renderData.isCacheKline = 1;
                _this.renderKP(true);
            }
            base.log("render-0");
            base.log(_this.renderData);
        },
        renderKP: function(status) {
            var _this = this;
            $('.container .second-screen').html(_.template($('#second-screen-tpl').html())({
                data: _this.renderData
            }));

            if (status) {
                _this.buildKLine({
                    mountDom: "#shanghai-canvas",
                    data: _this.renderData[_this.common.riseType].kdata
                });
            }
            _this.buildPie({
                mountDom: "#pie-canvas",
                data: _this.renderData.pieData
            });

            //判断行业分布展开是否超过两行超过加省略号添加展开功能
            if (dataHandling.countLines(document.querySelector('.industrial-distribution .content')) > 2) {
                var text = dataHandling.cutstr(_this.renderData.pieDataList, 70, "...");
                $('.industrial-distribution .content .txt').text(text).parent().addClass("open");
            }
            //事件绑定
            _this.bindEvent();
        },
        /**
         * [renderMemberScreen 渲染k线]
         * @return {[type]} [description]
         */
        renderMemberScreen: function() {
            var _this = this;
            $('.container .second-screen .kline-wrap').html(_.template($('#member-screen-tpl').html())({
                data: _this.renderData
            }));
            this.buildKLine({
                mountDom: "#shanghai-canvas",
                data: _this.renderData[_this.common.riseType].kdata
            });
            this.bindEvent();
        },
        /**
         * [renderShenzhen 深证指数]
         * @param  {[type]} data [description]
         * @return {[type]}      [description]
         */
        renderShenzhen: function(data) {
            var _this = this;
            var detail = {
                buyNum: '', //买入次数
                sellNum: '', //卖出次数
                tradeNum: '', //总次数
                profitLoss: '', //当日盈亏金额
                list: [],
                indexDate: '',
                range: '',
                currency: ''
            };
            if (this.renderData.maxPoint) {
                var key = this.renderData.maxPoint;
                var info = this.renderData.buySellList[key];
                //保存首个日期
                this.renderData[_this.common.riseType].dateCurrent = key;
                //获取最新买卖点索引
                var index = _this.renderData[_this.common.riseType].lastIndex = dataHandling.getIndexFromMostArray(_this.renderData[_this.common.riseType].kdata.list, key);
                if (index >= 0) {
                    detail = {
                        buyNum: info.buyNum, //买入次数
                        sellNum: info.sellNum, //卖出次数
                        tradeNum: info.tradeNum, //总次数
                        profitLoss: info.detailInfo && info.detailInfo.profitLoss || 0, //当日盈亏金额
                        list: info.detailInfo && info.detailInfo.zlist || [],
                        indexDate: info.indexDate,
                        range: dataHandling.getRange(_this.renderData[_this.common.riseType].kdata.list[index][5]),
                        currency: _this.renderData.currency
                    }
                }
                this.renderData[this.common.riseType] = _.extend(this.renderData[this.common.riseType], { firstData: detail });
            }

            //生成深圳指数K线
            this.renderData.isShowKline === "1" && this.buildKLine({
                mountDom: "#shenzhen-canvas",
                data: _this.renderData[_this.common.riseType].kdata
            });

            base.log("render-1");
            base.log(_this.renderData);
            //生成交易数据 
            this.renderTradeHtml(detail);
        },
        /**
         * [renderTradeHtml 渲染交易数据]
         * @return {[type]} [description]
         */
        renderTradeHtml: function(data) {
            var _this = this;
            data.riseType = _this.common.riseType;
            $(".tab-pannel .item:eq(" + this.common.riseType + ") .info").html(_.template($('#trade-list-tpl').html())({
                data: data
            }));
            this.bindEvent();
        },
        /**
         * [buildPie 生成圆数据]
         * @return {[type]} [description]
         */
        buildPie: function(option) {
            if (option) {
                new chart({
                    dom: option.mountDom,
                    saveImg: true,
                    series: [{
                        clockwise: true,
                        type: "pie",
                        startAngle: 0,
                        radius: $("#pie-canvas").width() / 2,
                        solid: false,
                        inSideCircleRadius: $("#pie-canvas").width() / 2 - 13,
                        transparent: true,
                        data: option.data,
                        lineStyle: {
                            strokeStyle: "#fff"
                        }
                    }]
                });
            }
        },
        /**
         * [buildKLine 生成K线数据]
         * @return {[type]} [description]
         */
        buildKLine: function(option) {
            var _this = this;
            /**start 计算最近买卖点的起始位置**/
            var count = this.renderData[_this.common.riseType].kdata.list.length; //k线总数量
            var index = _this.renderData[_this.common.riseType].lastIndex; //买卖点最新索引值
            var startIndex = 0; //k线屏幕开始位置索引
            var endIndex = 0; //K线屏幕结束索引
            if (index >= 0) {
                if (index + 1 <= _this.common.kScreenMax) { //k线小于一屏
                    startIndex = 0;
                    endIndex = 0;
                } else if (count - index <= _this.common.kScreenMax) { //k线不满一屏
                    startIndex = index - (_this.common.kScreenMax - (count - index))
                    endIndex = count;
                } else { //k线超过一屏
                    startIndex = index;
                    endIndex = index + _this.common.kScreenMax - 1;
                }
                _this.renderData[_this.common.riseType].startIndex = startIndex;
                _this.renderData[_this.common.riseType].endIndex = endIndex;
                var currentIndex = _this.renderData[_this.common.riseType].currentIndex = _this.renderData[_this.common.riseType].lastIndex;
                /**end 计算最近买卖点的起始位置**/

                if (_this.renderData.maxPoint) {
                    var $line = $(".tab-pannel .item:eq(" + _this.common.riseType + ") .line");
                    var $dateBar = $(".tab-pannel .item:eq(" + _this.common.riseType + ") .date-bar");
                    var screenIndex = index - startIndex;
                    var width = ($line.parent().width() - 0); //2为k线左右留的距离
                    var perWidth = width / _this.common.kScreenMax;
                    var x = (screenIndex + 1) * perWidth - perWidth / 2 + 0; //加1 1为k线距左留的距离
                    var left = x - $dateBar.width() / 2;
                    var rightLimit = width - $dateBar.width();

                    if (left > rightLimit) {
                        left = rightLimit;
                    } else if (left <= 0) {
                        left = 0;
                    }

                    $dateBar.css({
                        left: left + "px",
                        display: 'block'
                    });

                    $line.css({
                        left: x + "px",
                        display: 'block'
                    });

                    var date = _this.renderData[_this.common.riseType].kdata.list[index][0];
                    $dateBar.text(dataHandling.formatDate(date, 3));
                }
            } else {
                _this.renderData[_this.common.riseType].startIndex = 0;
            }

            //显示滑动查看
            if (option.data.list.length > this.common.kScreenMax) {
                $(".tab-pannel .item:eq(" + _this.common.riseType + ") .more-txt").show();
            }

            base.log("rangeList=" + JSON.stringify({ min: _this.common.secondInterface.data.startDate, max: _this.common.secondInterface.data.endDate }));
            base.log("maskList=" + JSON.stringify({ min: _this.common.secondInterface.data.endDate, max: option.data.list[option.data.list.length - 1][0], maxWidth: true }));
            //返回处理后的k线数据
            new chart({
                dom: option.mountDom,
                defaultDataSize: _this.common.kScreenMax, //一屏显示的k线数量
                dataIndex: startIndex,
                series: [{
                    type: 'K',
                    min: option.data.min,
                    max: option.data.max,
                    data: option.data.list,
                    global: _this.renderData.buySellList,
                    rangeList: [
                        { min: _this.common.secondInterface.data.startDate, max: _this.common.secondInterface.data.endDate }
                    ],
                    maskList: [
                        { min: _this.common.secondInterface.data.endDate, max: option.data.list[option.data.list.length - 1][0], maxWidth: true }
                    ]
                }, ],
                drag: true,
                saveImg: true,
                //网格线
                grid: {
                    showYgridLine: true,
                    yLineStyle: {
                        lineWidth: 1,
                        strokeStyle: 'rgba(224,224,224,.5)'
                    },
                    yGridLine: [true, true, true, false]
                },
                scale: 1.03,
                flexible: {
                    left: 0,
                    top: 5,
                    right: 0,
                    bottom: 18
                },
                events: {
                    touchstart: function(x, that) {
                        _this.moveAction(x);
                    },
                    touchmove: function(x) {
                        _this.moveAction(x);
                    },
                    canvasChange: function(rangeNumber, that) {
                        //增加限制超过一屏滑动
                        // $(".canvas-wrap .line").css({
                        //     display: 'none'
                        // });
                        // $(".canvas-wrap .date-bar").css({
                        //     display: 'none'
                        // });
                        _this.pointerMove(rangeNumber);

                        document.querySelector(that.option.dom).querySelector("img").style.display = "none";
                        that.canvas.style.display = "block";
                    },
                    touchend: function(that) {
                        _this.range = _this.range || 0;
                        _this.renderData[_this.common.riseType].startIndex = _this.renderData[_this.common.riseType].startIndex - _this.range; //开始数值
                        _this.renderData[_this.common.riseType].currentIndex = _this.renderData[_this.common.riseType].currentIndex - _this.range; //开始数值
                        _this.range = 0;
                        _this.canvasToImg(that);
                    }
                },
                xAxis: {
                    alignment: "justify", // justify 两端对齐
                    data: [{
                            label: dataHandling.formatDate(_this.renderData[_this.common.riseType].kdata.list[0][0], 3),
                            textStyle: { textAlign: 'left', fillStyle: '#999' }
                        },
                        {
                            label: dataHandling.formatDate(_this.common.secondInterface.data.endDate, 3),
                            textStyle: { textAlign: 'right', fillStyle: 'transparent' }
                        }
                    ],
                    margin: [13, 5],
                    textStyle: {
                        font: '12px PingFangSC-Regular',
                    },
                    lineStyle: {
                        lineWidth: .5,
                        strokeStyle: '#d6d6d6'
                    }
                },
                yAxis: {
                    show: false,
                    avgNum: 1,
                    margin: 5,
                    labelAlign: 'inside',
                    basisPoint: false,
                    textStyle: {
                        font: '10px PingFangSC-Regular',
                        fillStyle: '#C5C5C5'
                    },
                    formatter: function(value) {
                        return value.toFixed(2);
                    }
                }
            });
        },
        /**
         * [canvasToImg canvas保存图片]
         * @param  {[type]} that [description]
         * @return {[type]}      [description]
         */
        canvasToImg: function(that) {
            var canvas = that.canvas;
            var width = that.width;
            var height = that.height;

            var dataURL = canvas.toDataURL();
            var parentNode = canvas.parentNode;
            var imgNode = document.createElement('img');
            imgNode.id = canvas.id + "-img";
            // imgNode.width = width;
            // imgNode.height = height;
            imgNode.src = dataURL;
            //parentNode.appendChild(imgNode); 
            parentNode.replaceChild(imgNode, canvas.parentNode.querySelector("img"));

            canvas.style.display = "none";
            imgNode.style.display = "block";
        },
        /**
         * [pointerMove 滑动范围限定]
         * @param  {[type]} range [description]
         * @return {[type]}       [description]
         */
        pointerMove: function(range) {
            var countLen = this.renderData[this.common.riseType].kdata.list.length, //总数量
                startIndex = this.renderData[this.common.riseType].startIndex - range, //开始数值
                screenLen = this.common.kScreenMax; //一屏显示数量
            if (startIndex <= 0) {
                this.range = this.renderData[this.common.riseType].startIndex - 0;
                this.moveCanvas(this.renderData[this.common.riseType].currentIndex - this.range);
            } else if (startIndex + screenLen >= countLen) {
                this.range = this.renderData[this.common.riseType].startIndex - (countLen - screenLen);
                this.moveCanvas(this.renderData[this.common.riseType].currentIndex - this.range);
            } else if ((startIndex > 0) && (startIndex + screenLen < countLen)) {
                this.range = range;
                this.moveCanvas(this.renderData[this.common.riseType].currentIndex - range);
            }
        },
        /**
         * [moveCanvas canvas滑动事件]
         * @param  {[type]} currentIndex [description]
         * @return {[type]}              [description]
         */
        moveCanvas: function(currentIndex) {
            if (!isNaN(currentIndex)) {
                var _this = this;
                var key = _this.renderData[_this.common.riseType].kdata.list[currentIndex][0];
                this.renderData[this.common.riseType].dateCurrent = key;
                var $dateBar = $(".tab-pannel .item:eq(" + _this.common.riseType + ") .date-bar");

                var date = _this.renderData[_this.common.riseType].kdata.list[currentIndex][0];
                $dateBar.text(dataHandling.formatDate(date, 3));

                var interTime = function() {
                    var detailList = _this.renderData.buySellList[key];
                    if (_this.timer) {
                        clearTimeout(_this.timer);
                    }
                    _this.timer = setTimeout(function() {
                        var detail = {
                            list: []
                        }
                        if (detailList) {
                            detail = {
                                buyNum: detailList.buyNum || 0,
                                sellNum: detailList.sellNum || 0,
                                tradeNum: detailList.tradeNum || 0,
                                profitLoss: detailList.detailInfo && detailList.detailInfo.profitLoss || 0,
                                list: detailList.detailInfo && detailList.detailInfo.zlist || [],
                                range: dataHandling.getRange(_this.renderData[_this.common.riseType].kdata.list[currentIndex][5]),
                                currency: _this.renderData.currency
                            };
                        }
                        _this.renderTradeHtml(detail);
                    }, 300);
                }

                if (key && _this.renderData.buySellList[key] && !_this.renderData.buySellList[key].detailInfo.zlist) {
                    _this.common.buySellPoint.data.date = key;
                    _this.getDaySellListTime.abort();
                    _this.getDaySellList().done(function(list) {
                        _this.renderData.buySellList[key].detailInfo.zlist = list.list;
                        interTime();
                    });
                } else {
                    interTime();
                }

            }
        },
        /**
         * [moveAction canvas坐标移动]
         * @param  {[type]} x [description]
         * @return {[type]}   [description]
         */
        moveAction: function(x) {

            var _this = this;
            var index = x.index + (x.curIndex || 0);
            _this.range = 0;
            _this.renderData[_this.common.riseType].currentIndex = index;
            // if (index > _this.renderData[_this.common.riseType].kdata.list.length - 1) {
            //     return;
            // }
            var key = _this.renderData[_this.common.riseType].kdata.list[index][0];
            var moveTime = new Date(dataHandling.formatDate(key, 3)).getTime();
            var endTime = new Date(dataHandling.formatDate(this.common.secondInterface.data.endDate, 3)).getTime();
            if (moveTime > endTime) {
                return;
            }
            var $line = $(".tab-pannel .item:eq(" + _this.common.riseType + ") .line");
            var $dateBar = $(".tab-pannel .item:eq(" + _this.common.riseType + ") .date-bar");
            var width = $line.parent().width();

            var left = x.value - $dateBar.width() / 2;
            var rightLimit = width - $dateBar.width();

            if (left > rightLimit) {
                left = rightLimit;
            } else if (left <= 0) {
                left = 0;
            }
            $dateBar.css({
                left: left + "px",
                display: 'block'
            });

            $line.css({
                left: x.value + "px",
                display: 'block'
            });

            //保存当前日期
            _this.renderData[_this.common.riseType].dateCurrent = key;
            $dateBar.text(dataHandling.formatDate(key, 3));



            var interTime = function() {
                var detailList = _this.renderData.buySellList[key];
                if (_this.timer) {
                    clearTimeout(_this.timer);
                }
                _this.timer = setTimeout(function() {
                    var detail = {
                        list: []
                    }
                    if (detailList) {
                        detail = {
                            buyNum: detailList.buyNum || 0,
                            sellNum: detailList.sellNum || 0,
                            tradeNum: detailList.tradeNum || 0,
                            profitLoss: detailList.detailInfo && detailList.detailInfo.profitLoss || 0,
                            list: detailList.detailInfo && detailList.detailInfo.zlist || [],
                            range: dataHandling.getRange(_this.renderData[_this.common.riseType].kdata.list[index][5]),
                            currency: _this.renderData.currency
                        };
                    }
                    _this.renderTradeHtml(detail);
                }, 300);
            }

            if (key && _this.renderData.buySellList[key] && !_this.renderData.buySellList[key].detailInfo.zlist) {
                _this.common.buySellPoint.data.date = key;
                _this.getDaySellListTime.abort();
                _this.getDaySellList().done(function(list) {
                    _this.renderData.buySellList[key].detailInfo.zlist = list.list;
                    interTime();
                });
            } else {
                interTime();
            }
        },
        /**
         * [swiper swiper生成]
         * @return {[type]} [description]
         */
        swiper: function() {
            var $switch = $(".income-analysis .switch-more");
            this.swiperList = new Swiper('.swiper-container', {
                resistanceRatio: 0,
                onReachBeginning: function(swiper) {
                    $switch.show();
                },
                onReachEnd: function(swiper) {
                    $switch.hide();
                }
            });
        },
        /**
         * [setDomPosition 收益分析图标位置处理]
         * @param {[type]} dom1 [description]
         * @param {[type]} dom2 [description]
         * @param {[type]} dom3 [description]
         */
        setDomPosition: function(dom1, dom2, dom3) {
            var x1 = dom1.height() / 2 - dom2.height() / 2;
            var x2 = dom1.height() / 2 - dom3.height() / 2;
            x2 = x2 < 0 ? 0 : x2;
            x1 = x1 - x2 < 2 ? 2 : x1 - x2;
            dom3.css({ "bottom": x2 });
            dom2.css({ "bottom": x1 });
        },
        /**
         * [bindEvent 页面事件绑定]
         * @return {[type]} [description]
         */
        bindEvent: function() {
            var $dateSegment = $(".date-segment");
            var $incomeAnalysisRight = $(".income-analysis .right");
            var _this = this;

            //重新刷新页面
            $(".reload").off("click").on("click",function(){
                window.location.reload(true);
            });

            //返回
            $(".reback").off("click").on("click",function(){
                base.href("http://action:3413");
            });
            //行业分布内容展开
            $('.industrial-distribution .content').off("click").on("click", function() {
                var $this = $(this);
                if ($this.hasClass("open")) {
                    $('.industrial-distribution .content .txt').text(_this.renderData.pieDataList);
                    $(this).removeClass("open").addClass("close");
                } else {
                    $('.industrial-distribution .content .txt').text(dataHandling.cutstr(_this.renderData.pieDataList, 70, "..."));
                    $(this).removeClass("close").addClass("open");
                }

            });
            /*---------------日期选择器-------------------*/
            $(".date-select .date").off("click").on("click", function(e) {
                var isHidden = $dateSegment.is(":hidden");
                var $this = $(this);
                if (isHidden) {
                    $dateSegment.removeClass("hidden");
                    $this.addClass("open").removeClass("close");
                } else {
                    $dateSegment.addClass("hidden");
                    $this.addClass("close").removeClass("open");

                }
                TalkingData.onHTSCEvent("click", "leaf304", "持仓综合分析", "", "选择日期");

                e.stopPropagation();
            });

            //选择阶段
            $(".time-quantum").off("click").on("click", function() {
                var $this = $(this),
                    index = $this.index(),
                    flag = $this.attr("data-flag"),
                    type = $this.find(".type").text(),
                    text = $this.find(".txt").text(),
                    $dateInput = $(".date-select .date");
                $this.addClass("active").siblings().removeClass("active");
                TalkingData.onHTSCEvent("click", "leaf304", "持仓综合分析", "", "选择日期下拉菜单选项详情_" + type);
                if (flag && !(_this.renderData.dateIndex === index)) {
                    _this.common.dateIndex = index;
                    _this.common.dateType = flag;
                    $dateInput.text(text);
                    //获取日期参数提供给接口   
                    //清除自定义时间
                    file.deleteAll(_this.common.temp, function(data) {
                        _this.renderData.startDate = _this.renderData.dateList[index].startDateParam;
                        _this.renderData.endDate = _this.renderData.dateList[index].endDateParam;
                        _this.getData();
                    });
                }
                $dateSegment.removeClass("hidden");
            });
            //关闭选择时间弹框
            $(".container").on("click", function() {
                $(".date-segment").addClass("hidden");
                $(".date-select .date").removeClass("open").addClass("close");
            });
            //链接跳转
            $("[data-url]").off("click").on("click", function() {
                var $this = $(this);

                var index = $this.attr("data-index"),
                    key = $this.attr("data-url");

                var url = _this.common.linkUrl[key](index);
                base.log("url=" + url);
                if (url) {
                    base.href(url);
                }
                return;
            });

            //收益分析切换
            $(".switch-more").off("click").on("click", function() {
                if (!_this.swiperList.activeIndex) {
                    _this.swiperList.slideNext();
                }
            });

            //上证深圳指数切换
            $(".tab-list .item").off("click").on("click", function() {
                var $this = $(this),
                    index = $this.index();
                $this.addClass("cur").siblings().removeClass("cur");
                $(".tab-pannel .item:eq(" + index + ")").removeClass("hidden").siblings().addClass("hidden");
                _this.common.riseType = index;
                _this.renderData.riseType = index;
                //埋点 0对比上证 1对比深证
                TalkingData.onHTSCEvent("click", "leaf304", "持仓综合分析", "tab", index ? "对比深证" : "对比上证");
                //上证或深圳已经获取过就不在调用接口
                if (!_this.common.run[_this.common.riseType]) {
                    _this.getSecondProcess();
                }
            });

            //页面滚动到一定位置加载第二屏
            $(".main").scroll(function() {
                //判断第一屏加载完 并且 第二屏未加载过 加载第二屏数据
                if ($(this).scrollTop() > 50 && !_this.common.secondInterface.run && _this.common.firstInterface.loadEnd) {
                    //获取第二屏接口 
                    _this.getSecondProcess();
                }
            });

            //渲染会员数据
            $("#memberRender").off("click").on("click", function() {
                TalkingData.onHTSCEvent("page", "leaf304", "持仓综合分析", "", "升级VIP会员");
                file.insert(_this.common.tempKline, { isCacheKline: 1 }, function(data) {
                    _this.renderMemberScreen();
                });
            });
        }
    };

    return new process();
});